package com.juc.semaphore.semaphore6;

import java.util.concurrent.Semaphore;

public class Service {
    /***
     * acquireUninterruptibly 是使等待进入acquire() 方法的线程 不能被打断
     */
    private Semaphore semaphore = new Semaphore(1);

    public void testMethod(){
            semaphore.acquireUninterruptibly();
            System.out.println(Thread.currentThread().getName() + " begin timer = " + System.currentTimeMillis());
            for (int i = 0; i < Integer.MAX_VALUE ; i++) {
                String newString  =new String();
                Math.random();
            }
            System.out.println(Thread.currentThread().getName() + " end timer = " + System.currentTimeMillis());
            semaphore.release();
    }
}
